const { LOGPRE, writeToTxtFile } = require("./src/helper");
const { runBot } = require("./src/bot");
const express = require("express");
const app = express();
app.use((req, res, next) => {
  res.header("Access-Control-Allow-Origin", "*");
  next();
});
let qrcode = "";
// 返回登录二维码的接口
app.get("/qrcode", (req, res) => {
  if (qrcode) {
    // 返回二维码地址给前端
    res.json({ qrcode });
  } else {
    res.status(404).json({ error: "QR Code not found" });
  }
});

app.listen(3000, async () => {
  console.log(LOGPRE, "http://localhost:3000/qrcode");
  qrcode = (await runBot()) || "";
});
